<?php 
class Common_model extends CI_Model
{
	var $member=array();
	public function __construct()
	{
		$this->member[0]='student';
		$this->member[1]='teacher';
		$this->member[2]='educator';
		$this->member[3]='parent';
		$this->member[4]='institute';
		$this->email_setting = $this->lang->line('email');
	}
	public function is_student()
	{
		 if($this->session->userdata('member_type')==$this->member[0])
		 return true;
		 else  return false;
	}
	public function is_teacher()
	{
		 if($this->session->userdata('member_type')==$this->member[1])
		 return true;
		 else  return false;
	}
	public function is_educator()
	{
		 if($this->session->userdata('member_type')==$this->member[2])
		 return true;
		 else  return false;
	}
	public function is_parent()
	{
		  if($this->session->userdata('member_type')==$this->member[3])
		  return true;
		  else  return false;
	}
	public function is_institute()
	{
		 if($this->session->userdata('member_type')==$this->member[4])
		 return true;
		 else  return false;
	}
	public function is_user_logged_in()
	{
		 if($this->session->userdata('logedin'))
		 return $this->session->userdata('member_type');
		 else return false;
	}
	public function join_in($login_detials = array(), $remember_user = FALSE)
	{
		if (empty($login_detials['password']) || empty($login_detials['email']) || !$this->verify_email($login_detials['email']))
	    {
			return FALSE;
	    }
				
		$sql_where = array('email' => $login_detials['email'], 'password' => $login_detials['password']);
		$query = $this->db->where($sql_where)->get($this->db->dbprefix('members'));
			
	    // User exists, now validate credentials.
		if ($query->num_rows() == 1)
	    {	
			if (isset($query->row()->activation) && $query->row()->activation!='NULL')
			{
					return FALSE;
			}
			// Check whether account has been activated.
			if (isset($query->row()->active) && $query->row()->active!= 'Y')
			{
				return FALSE;
			}
			
			if ($remember_user == 1)
			{
				$this->remember_user();
			}
			else
			{
				delete_cookie('remember_me_token');
			}

			$data=array(
						'id'=>$query->row()->member_id,
						'logedin'=>TRUE,
						'member_type'=>$query->row()->member_type,
						'email'=>$query->row()->email,
						);
						
			$this->set_login_sessions($data);
			$this->insert_login_detials($query->row()->member_id);
			return TRUE;
	    }
	    return FALSE;
	}
	public function verify_member($identity, $verify_password)
	{
		if (empty($identity) || empty($verify_password))
		{
			return FALSE;
		}
		$sql_select = array(
			'email',
			'password'
		);
		$sql_where = array(
			'email'=>$identity,
			'password'=>$verify_password
		);
		$query = $this->db->select($sql_select)->where($sql_where)->limit(1)->get($this->db->dbprefix('members'));
	    $result = $query->row();

	    if ($query->num_rows() > 0)
	    {
			return TRUE;
	    }		
		return FALSE;
	}
	public function is_active($email)
	{
		if (empty($email))
		{
			return FALSE;
		}
		$sql_select = array(
			'email',
			'activation',
			'active'
		);
		$sql_where = array(
			'email'=>$email
		);
		$query = $this->db->select($sql_select)->where($sql_where)->limit(1)->get($this->db->dbprefix('members'));
                $resultData = array();
	    if ($query->num_rows() > 0)
	    {
		$resultData = $query->result_array();
		
			if($query->row()->activation == 'NULL' && $query->row()->active == 'Y')
			{
				return TRUE;
			}
			else
			{
			   return FALSE;	
			}
	    }		
else{
		return FALSE;
}
	}
	public function verify_email($email)
	{
		if (empty($email))
		{
			return FALSE;
		}
				
		$sql_select = array('email');
		$sql_whrere=array('email'=>$email);
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('members'));		 
	    $result = $query->row();

	    if ($query->num_rows() > 0)
	    {
			return $query->row()->email;
	    }		
		return FALSE;
	}
	public function remember_user()
	{
		    $this->config->set_item('sess_expire_on_close', FALSE); //'remember' is checkbox name.
			$random_string = md5(time().'COOKIENAMESET');
			$cookie = array(
				'name'   => 'remember_me_token',
				'value'  => $random_string,
				'expire' => '1209600',  // Two weeks
				'domain' => '',
				'path'   => '/'
			);
		  set_cookie($cookie);
	}
	public function set_login_sessions($data)
	{
		 $this->session->set_userdata($data);
		 if($this->session->userdata('logedin'))
		 return true;
		 else return false;
	}
	public function insert_login_detials($member_id)
	{
		    $type='Web';
		    if($this->agent->is_mobile())
			$type = 'Mobile';	
			
			$lat=$long=0;
			$ip_addr = $_SERVER['REMOTE_ADDR'];
			$geoplugin = @unserialize( file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip_addr) );
			if (is_numeric($geoplugin['geoplugin_latitude']) && is_numeric($geoplugin['geoplugin_longitude']) ) 
			{
				$lat = $geoplugin['geoplugin_latitude'];
				$long = $geoplugin['geoplugin_longitude'];
			}
			$date=date('Y-m-d H:i:s');
			$sql_insert['member_id_fk']=$member_id;
			$sql_insert['login_latitute']=$lat;
			$sql_insert['login_longitute']=$long;
			$sql_insert['login_device_type']=$type;
			$sql_insert['login_ip']=$ip_addr;
			$sql_insert['login_time']=time();
			$sql_insert['created_date']=$date;
			
		    $this->db->insert($this->db->dbprefix('member_login_details'), $sql_insert);
	}
	public function insert_data($tablename,$insert_data=array())
	{   
		if(count($insert_data)>0)
		{
			if(count($tablename)>0)
			{
				$this->db->insert($this->db->dbprefix($tablename),$insert_data);
				return $this->db->insert_id();
			}
		}
	}
	public function class_list()
	{
		$sql_select = array('class_id','class_description');
		$query=$this->db->select($sql_select)->order_by("class_id","asc")->get($this->db->dbprefix('classes'));
		$data=null;
	    if ($query->num_rows() > 0)
	    {
			$count=0;
			$data2=array();
			foreach($query->result_array() as $row)
			{
				$data2[$row['class_id']]=$row['class_id'];
			}
			ksort($data2);
			foreach($data2 as $row)
			{
				if($count%2==0)
				$data.='<span class="content_pink detail join_as_detail_class" id="'.$row.'">'.$row.'<span style="font-size:14px;"><sup>th</sup>&nbsp;</span></span>';
				else $data.='<span class="content_blue detail join_as_detail_class" id="'.$row.'">'.$row.'<span style="font-size:14px;"><sup>th</sup>&nbsp;</span></span>';
				
				$count++;
			}
	    }		
		return trim($data,',');
	}
	public function school_list($value='')
	{
		$sql_select = array('school_id','name');
		$sql_where = 'name LIKE '."'$value%' ";
		$query=$this->db->select($sql_select)->where($sql_where)->order_by("name","asc")->limit(2)->get($this->db->dbprefix('school'));
	    $data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_school a1" id="'.$row['school_id'].'">'.$row['name'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_school" id="'.$row['school_id'].'">'.$row['name'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function board_list($value='')
	{
		$sql_select = array('exam_id','full_name');
		$sql_where = 'full_name LIKE '."'$value%'".' or exam_id LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('exams'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_board" id="'.$row['exam_id'].'">'.$row['full_name'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_board" id="'.$row['exam_id'].'">'.$row['full_name'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function book_list($value='')
	{
		$sql_select = array('book_id','book_title');
		$sql_where = "(book_title LIKE '".$value['search']."%') and subject_id='".$value['subject']."' and class_id='".$value['class']."'";
		$query=$this->db->select($sql_select)->where($sql_where)->get($this->db->dbprefix('books'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_book" id="'.$row['book_id'].'">'.$row['book_title'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_book" id="'.$row['book_id'].'">'.$row['book_title'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function chapter_list($value='')
	{
		$sql_select = array('chapter_number', 'chapter_title');
		$sql_where = "book_id = '".$value['book']."' group by chapter_number";
		$query=$this->db->select($sql_select)->where($sql_where)->get($this->db->dbprefix('reviewed_chapter_masters'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_chapter white-tooltip" data-toggle="tooltip" data-placement="top" title="'.$row['chapter_title'].'" id="'.$row['chapter_number'].'">'.$row['chapter_number'].'<span style="font-size:14px;"><sup>th</sup>&nbsp;</span></span>';
				else $data.='<span class="content_pink detail join_as_detail_chapter white-tooltip" data-toggle="tooltip" data-placement="top" title="'.$row['chapter_title'].'" id="'.$row['chapter_number'].'">'.$row['chapter_number'].'<span style="font-size:14px;"><sup>th</sup>&nbsp;</span></span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function subject_list($value='')
	{
		$sql_select = array('subject_id','description');
		$sql_where = 'description LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('subjects'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_subject" id="'.$row['subject_id'].'">'.$row['description'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_subject" id="'.$row['subject_id'].'">'.$row['description'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function city_list($value='')
	{
		$sql_select = array('city_id','city_name');
		$sql_where = 'city_name LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('city'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_city" id="'.$row['city_id'].'">'.$row['city_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_city" id="'.$row['city_id'].'">'.$row['city_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function city_list_state($value='',$state='')
	{
		$sql_select = array('city_id','city_name');
		$sql_where = 'city_name LIKE '."'$value%'".' and state_id="'.$state.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('city'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_city" id="'.$row['city_id'].'">'.$row['city_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_city" id="'.$row['city_id'].'">'.$row['city_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function city_list_state1($value='',$state='')
	{
		$sql_select = array('city_id','city_name');
		$sql_where = 'city_name LIKE '."'$value%'".' and state_id="'.$state.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('city'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_city1" id="'.$row['city_id'].'">'.$row['city_name'].' </span>,';
				else $data.='<span class="content_pink detail join_as_detail_city1" id="'.$row['city_id'].'">'.$row['city_name'].' </span>,';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function city_list_state2($value='',$state='')
	{
		$sql_select = array('city_id','city_name');
		$sql_where = 'city_name LIKE '."'$value%'".' and state_id="'.$state.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('city'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_city2" id="'.$row['city_id'].'">'.$row['city_name'].' </span>,';
				else $data.='<span class="content_pink detail join_as_detail_city2" id="'.$row['city_id'].'">'.$row['city_name'].' </span>,';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function state_list($value='')
	{
		$sql_select = array('state_id','state_name');
		$sql_where = 'state_name LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('state'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_state" id="'.$row['state_id'].'">'.$row['state_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_state" id="'.$row['state_id'].'">'.$row['state_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function state_list_country($value='',$country='')
	{
		$sql_select = array('state_id','state_name');
		
		$sql_where = 'state_name LIKE '."'$value%'".'and country_id="'.$country.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('state'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_state" id="'.$row['state_id'].'">'.$row['state_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_state" id="'.$row['state_id'].'">'.$row['state_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function state_list_country1($value='',$country='')
	{
		$sql_select = array('state_id','state_name');
		$sql_where = 'state_name LIKE '."'$value%'".'and country_id="'.$country.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('state'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_state1" id="'.$row['state_id'].'">'.$row['state_name'].' </span>,';
				else $data.='<span class="content_pink detail join_as_detail_state1" id="'.$row['state_id'].'">'.$row['state_name'].' </span>,';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	

public function state_list_country2($value='',$country='')
	{
		$sql_select = array('state_id','state_name');
		$sql_where = 'state_name LIKE '."'$value%'".'and country_id="'.$country.'"';
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('state'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_state2" id="'.$row['state_id'].'">'.$row['state_name'].' </span>,';
				else $data.='<span class="content_pink detail join_as_detail_state2" id="'.$row['state_id'].'">'.$row['state_name'].' </span>,';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function country_list($value='')
	{
		$sql_select = array('country_id','country_name');
		$sql_where = 'country_name LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('country'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_country" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_country" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function country_list1($value='')
	{
		$sql_select = array('country_id','country_name');
		$sql_where = 'country_name LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('country'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_country1" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_country1" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	
	public function country_list2($value='')
	{
		$sql_select = array('country_id','country_name');
		$sql_where = 'country_name LIKE '."'$value%'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('country'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_country2" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				else $data.='<span class="content_pink detail join_as_detail_country2" id="'.$row['country_id'].'">'.$row['country_name'].' </span>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function institute_list($value='')
	{
		$sql_select = array('institution_id','name');
		$sql_where = 'name LIKE '."'$value%'"."and category!='PG'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('institution'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_institute" id="'.$row['institution_id'].'">'.$row['name'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_institute" id="'.$row['institution_id'].'">'.$row['name'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function pg_list($value='')
	{
		$sql_select = array('institution_id','name');
		$sql_where = 'name LIKE '."'$value%'"."and category='PG'";
		$query=$this->db->select($sql_select)->where($sql_where)->limit(2)->get($this->db->dbprefix('institution'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_institute" id="'.$row['institution_id'].'">'.$row['name'].' </span>&nbsp;';
				else $data.='<span class="content_pink detail join_as_detail_institute" id="'.$row['institution_id'].'">'.$row['name'].' </span>&nbsp;';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
	public function check_email($value='')
	{
            $sql_select = array('member_id');
            $sql_where = 'email LIKE '."'%".$value."%'";
            $query = $this->db->select($sql_select)->where($sql_where)->get($this->db->dbprefix('members'));
            $data=null;
	    if ($query->num_rows()>0)
	    {
		return $data = 'An account with this email address already exists.';
	    }		
            else
            {
		return $data = 'success';
            }
	}
	public function check_email1($value='')
	{
            $sql_select = array('member_id');
            $sql_where = 'email = '."'".$value."'";
            $query = $this->db->select($sql_select)->where($sql_where)->get($this->db->dbprefix('members')); 
            return $query;
	}
	public function sent_forgot_email($member_identity)
	{
            if(empty($member_identity)) { return false;}
            $activation=base64_encode($member_identity);
            $reset_url = base_url().'index.php/reset_password?reset='.$activation;
            $replace_word = array("[ResetURL]");
            $replace_value = array($reset_url);
		//Set message
            $email_message=$this->email_setting['forgot']['message'];
            $email_message = str_replace($replace_word,$replace_value,$email_message);
            $this->email_send($member_identity, $email_message);
	}
	public function resetPassword($reset_email)
	{
            if(empty($reset_email)) { return false;}
            $data = array(
			'password'=>md5($this->input->post('password'))
			);
            $this->db->where('email',$reset_email);
            $query = $this->db->update('zrc_members',$data);
            $email_message=$this->email_setting['reset']['message'];	
            $this->email_send($reset_email,$email_message);	
	}

	public function join_as($data=array())
	{
		if(empty($data)){ return false;}
		$type = $data['member_type'];
		//--arrange tables--
		$table=array(
		'member'=>'members',
		'class'=>'member_classes',
		'institute'=>'member_institutes',
		'subject'=>'member_subjects',
		'school'=>'member_schools'
		);
		$date=date('Y-m-d H:i:s'); 
		$activation=md5($date.$data['email']);
		//Set link
		$reset_url = base_url().'index.php/account_activate/'.$activation;
		if($type == 'institute')
		{
			$name = $data['institute'];
		}
		else {
			$name = $data['first_name'];
		}
		$replace_word = array("[ResetURL]", "[url]", "[SPACER]", "[logo]", "[User]");
		$replace_value = array($reset_url, base_url().BASE, SKIN_URL_IMAGE.'/spacer.png', SKIN_URL_IMAGE.'/zigya_logo.png', $name);
		//Set message
		$email_message=$this->email_setting['join_as']['message'];
		$email_message = str_replace($replace_word,$replace_value,$email_message);
		switch($type)
		{
			 case 'student':
			 {
				//member data
				$member_data['first_name']=$data['first_name'];
				$member_data['last_name']=$data['last_name'];
				$member_data['email']=$data['email'];
				$member_data['password']=md5($data['password']);
	            $member_data['active']='N';
				$member_data['activation']=$activation;
				$member_data['created_date']=$date;
				$member_data['modified_date']=$date;
				$member_data['gender']=$data['gender'];
				$member_data['donor']='none';
				$member_data['member_type']=$data['member_type'];
				//class data
				$class_data['class_id_fk']=$data['class'];
				$class_data['created_date']=$date;
				$class_data['modified_date']=$date;
				//school data
				$school_data['section']=$data['section'];
				$school_data['school_id_fk']=$data['school'];
				$school_data['school_name']=$data['school_1'];
				$school_data['board_id_fk']=$data['board'];
				$school_data['board_name']=$data['board_1'];
				
				$school_data['created_date']=$date;
				$school_data['modified_date']=$date;
				$school_data['status']='Active';
				//insert member data
				$id=$this->common_model->insert_data($table['member'], $member_data);
			    if($id)
				{
					//insert profile data
					$school_data['member_id_fk']=$id;
					$class_data['member_id_fk']=$id;
					$this->common_model->insert_data($table['school'], $school_data);
					$this->common_model->insert_data($table['class'], $class_data);
					$this->email_send($data['email'],$email_message);
					return true;
				}
				else
				{
					return false;
				}
			 }
			 break;
			 case 'teacher':
			 {
				//member data
				$member_data['first_name'] = htmlspecialchars($data['first_name'],ENT_QUOTES);
				$member_data['last_name'] = htmlspecialchars($data['last_name'],ENT_QUOTES);
				$member_data['email'] = htmlspecialchars($data['email'],ENT_QUOTES);
				$member_data['password'] = md5($data['password']);
	            $member_data['active']='N';
				$member_data['activation']=$activation;
				$member_data['created_date']=$date;
				$member_data['modified_date']=$date;
			//	$member_data['gender']=$data['gender'];
				$member_data['donor']='none';
				$member_data['member_type'] = htmlspecialchars($data['member_type'],ENT_QUOTES);
				//class data
				$class_data['class_id_fk'] = htmlspecialchars($data['class'],ENT_QUOTES);
				$class_data['created_date']=$date;
				$class_data['modified_date']=$date;
				
	            //school data
				$school_data['school_id_fk'] = htmlspecialchars($data['school'],ENT_QUOTES);
				$school_data['school_name'] = htmlspecialchars($data['school_1'],ENT_QUOTES);
				$school_data['board_id_fk'] = htmlspecialchars($data['board'],ENT_QUOTES);
				$school_data['board_name'] = htmlspecialchars($data['board_1'],ENT_QUOTES);
				$school_data['created_date']=$date;
				$school_data['modified_date']=$date;
				
				//subject data
				$subject_data['subject_id_fk'] = htmlspecialchars($data['subject'],ENT_QUOTES);
				$subject_data['subject_name'] = htmlspecialchars($data['subject_1'],ENT_QUOTES);
				$subject_data['created_date']=$date;
				
				//insert member data
				$id=$this->common_model->insert_data($table['member'], $member_data);
			    if($id)
				{
					//insert profile data
					$school_data['member_id_fk']=$id;
					$subject_data['member_id_fk']=$id;
					$class_data['member_id_fk']=$id;
					$this->common_model->insert_data($table['school'], $school_data);
					$this->common_model->insert_data($table['class'], $class_data);
					$this->common_model->insert_data($table['subject'], $subject_data);
					$this->email_send($data['email'],$email_message);
					return true;
				}
				else
				{
					return false;
				}
			 }
			 break;
			 case 'educator':
			 {
				//member data
				$member_data['first_name']=$data['first_name'];
				$member_data['last_name']=$data['last_name'];
				$member_data['email']=$data['email'];
				$member_data['password']=md5($data['password']);
				$member_data['state_id_fk']=$data['state'];
				$member_data['donor']='none';
				$member_data['member_type']=$data['member_type'];
				 //school data
				$member_data['city_id_fk']=$data['city'];
				$member_data['city_name']=$data['city_1'];
				$member_data['state_id_fk']=$data['state'];
				$member_data['state_id_fk']=$data['state_1'];
	            $member_data['active']='N';
				$member_data['activation']=$activation;
				$member_data['created_date']=$date;
				$member_data['modified_date']=$date;
				$member_data['gender']=$data['gender'];
				//class data
				$class_data['class_id_fk']=$data['class'];
				$class_data['created_date']=$date;
				$class_data['modified_date']=$date;
				//subject data
				$subject_data['subject_id_fk']=$data['subject'];
				$subject_data['subject_name']=$data['subject_1'];
				$subject_data['created_date']=$date;
				 //school data
				$school_data['board_id_fk']=$data['board'];
				$school_data['board_name']=$data['board_1'];
				$school_data['created_date']=$date;
				$school_data['modified_date']=$date;
				//insert member data
				$id=$this->common_model->insert_data($table['member'], $member_data);
			    if($id)
				{
					//insert profile data
					$subject_data['member_id_fk']=$id;
					$class_data['member_id_fk']=$id;
					$school_data['member_id_fk']=$id;
					$this->common_model->insert_data($table['class'], $class_data);
					$this->common_model->insert_data($table['subject'], $subject_data);
					$this->common_model->insert_data($table['school'], $school_data);
					$this->email_send($data['email'],$email_message);
					return true;
				}
				else
				{
					return false;
				}
			 }
			 break;
			 case 'parent':
			 {
				//member data

                $member_data['first_name']=$data['first_name'];
				$member_data['last_name']=$data['last_name'];
				$member_data['email']=$data['email'];
				$member_data['password']=md5($data['password']);
	            $member_data['active']='N';
				$member_data['activation']=$activation;
				$member_data['created_date']=$date;
				$member_data['modified_date']=$date;
				$member_data['gender']=$data['gender'];
				$member_data['donor']='none';
				$member_data['member_type']=$data['member_type'];
				//class data
				$class_data['class_id_fk']=$data['class'];
				$class_data['created_date']=$date;
				$class_data['modified_date']=$date;
				 //school data
				$school_data['board_id_fk']=$data['board'];
				$school_data['board_name']=$data['board_1'];
				$school_data['school_id_fk']=$data['school'];
				$school_data['school_name']=$data['school_1'];
				$school_data['created_date']=$date;
				$school_data['modified_date']=$date;
				//insert member data
				$id=$this->common_model->insert_data($table['member'], $member_data);
			    if($id)
				{
					//insert profile data
					$school_data['member_id_fk']=$id;
					$class_data['member_id_fk']=$id;
					$this->common_model->insert_data($table['school'], $school_data);
					$this->common_model->insert_data($table['class'], $class_data);
					$this->email_send($data['email'],$email_message);
					return true;
				}
				else
				{
					return false;
				}
			 
			 }
			 break;
			 case 'institute':
			 {
				//member data
				$member_data['email']=$data['email'];
				$member_data['password']=$data['password'];
	            $member_data['active']='N';
				$member_data['activation']=$activation;
				$member_data['created_date']=$date;
				$member_data['modified_date']=$date;
				$member_data['gender']='O';
				$member_data['donor']='none';
				$member_data['member_type']=$data['member_type'];
				$member_data['country_id_fk']='IN';
				$member_data['city_id_fk']=$data['city'];
				$member_data['city_name']=$data['city_1'];
				$member_data['state_id_fk']=$data['state'];
				//intitute data
				$intitute_data['type']=$data['category'];
				$intitute_data['email']=$data['email'];
				$intitute_data['institute_id_fk']=$data['institute'];
				$intitute_data['institute_name']=$data['institute_1'];
				$intitute_data['city_id_fk']=$data['city'];
				$intitute_data['city_name']=$data['city_1'];
				$intitute_data['state_id_fk']=$data['state'];
				$intitute_data['phone_number']=$data['phone'];
				$intitute_data['modified_date']=$date;
				$intitute_data['created_date']=$date;
				//insert member data
				$id=$this->common_model->insert_data($table['member'], $member_data);
			    if($id)
				{
					//insert profile data
					$intitute_data['member_id_fk']=$id;
					$this->common_model->insert_data($table['institute'], $intitute_data);
					$this->email_send($data['email'],$email_message);
					return true;
				}
				else
				{
					return false;
				}
			 }
			 break;
			 default: return false;
		}
	}
	
	public function join_as_detail($data=array())
	{
		if(empty($data)){ return false;}
		$type = $data['member_type'];
		
		//--arrange tables--
		$table=array(
		'member'=>'members',
		'class'=>'member_classes',
		'institute'=>'member_institutes',
		'subject'=>'member_subjects',
		'school'=>'member_schools',
		'interest'=>'member_interests',
		'photo'=>'member_photos',
		'guardian'=>'member_guardians',
		'highlight'=>'member_highlight',
		'memories'=>'member_memories',
		'associations'=>'member_associations',
		'supw'=>'member_supws',
		'awards'=>'member_awards',
		'professions'=>'member_professions',
		'hobbies'=>'member_hobbies',
		'interest'=>'member_interests',
		'hobby_master'=>'hobby_master',
		'book'=>'member_books'
		);
		$date=date('Y-m-d H:i:s');
		if(isset($data['email']))
		{
                    $activation=md5($date.$data['email']);
                    //Set link
                    $reset_url = base_url().'index.php/account_activate/'.$activation;
                    $name = $data['first_name'];
                    $replace_word = array("[ResetURL]", "[url]", "[SPACER]", "[logo]", "[User]");
                    $replace_value = array($reset_url, base_url().BASE, SKIN_URL_IMAGE.'/spacer.png', SKIN_URL_IMAGE.'/zigya_logo.png', $name);
                    //Set message
                    $email_message=$this->email_setting['join_as']['message'];
                    $email_message = str_replace($replace_word,$replace_value,$email_message);
		}
		Switch($type)
		{
			case 'student':
			{
				if($data['part'] == 'personal')
				{
					//member data
					if(isset($data['first_name']))$member_data['first_name']=$data['first_name'];
					if(isset($data['last_name']))$member_data['last_name']=$data['last_name'];
					if(isset($data['email']))$member_data['email']=$data['email'];
					if(isset($data['password']))$member_data['password']=md5($data['password']);
		            $member_data['active']='N';
					if(isset($activation))
					{
						$member_data['activation']=$activation;
					}
					$member_data['created_date']=$date;
					$member_data['modified_date']=$date;
					if(isset($data['gender']))$member_data['gender']=$data['gender'];
					$member_data['donor']='none';
					if(isset($data['member_type']))$member_data['member_type']=$data['member_type'];
					if(isset($data['tagline']))$member_data['tagline']=trim($data['tagline']);
					if(isset($data['alias']))$member_data['alias']=trim($data['alias']);
					if(isset($data['phone_number']))$member_data['phone_number']=$data['phone_number1'];
					if(isset($data['dob']))$member_data['dob']=date('Y-m-d 00:00:00' ,strtotime($data['dob']));
					if(isset($data['home_address']))$member_data['address1']=trim($data['home_address']);
					if(isset($data['city']))$member_data['city_id_fk']=$data['city'];
					if(isset($data['city_1']))$member_data['city_name']=$data['city_1'];
					if(isset($data['state']))$member_data['state_id_fk']=$data['state'];
					if(isset($data['country']))$member_data['country_id_fk']=htmlspecialchars($data['country'],ENT_QUOTES);
					if(isset($data['postal_code']))$member_data['pin_code']=$data['postal_code'];
					
					//insert member data
					$id=$this->common_model->insert_data($table['member'], $member_data);
				    if($id){ 
                                        $this->email_send($data['email'],$email_message);
                                        return $id; 
                                    }
					else{ return ''; }
				}
				if($data['part'] == 'academic_school')
				{
					//school data
					if(isset($data['member_id']))$school_data['member_id_fk']=$data['member_id'];
					if(isset($data['school_1']))$school_data['school_name']=$data['school_1'];
					if(isset($data['school']))$school_data['school_id_fk']=$data['school'];
					if(isset($data['section']))$school_data['section']=$data['section'];
					if(isset($data['admission_no']))$school_data['admission_no']=$data['admission_no'];
					if(isset($data['year_start']))$school_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$school_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
		            $school_data['status']='Active';
					$school_data['created_date']=$date;
					$school_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['school'], $school_data);
					
					//class data
					if(isset($data['member_id']))$class_data['member_id_fk']=$data['member_id'];
					$class_data['class_id_fk']=$data['class'];
					$class_data['created_date']=$date;
					$class_data['modified_date']=$date;
					//insert school data
					$id4=$this->common_model->insert_data($table['class'], $class_data);
					
					//highlight1 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights']))$high_data['highlight_desc']=$data['highlights'];
						$high_data['highlight_for']='School';
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['highlight'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlight2']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlight2']))$high1_data['highlight_desc']=$data['highlight2'];
						$high_data['highlight_for']='School';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//highlight3 data
					if(isset($data['highlight3']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlight3']))$high2_data['highlight_desc']=$data['highlight3'];
						$high_data['highlight_for']='School';
						$high2_data['status']='Active';
						$high2_data['created_date']=$date;
						
						$id3=$this->common_model->insert_data($table['highlight'], $high2_data);
					}
					
					//memories data
					if(isset($data['memories']))
					{
						if(isset($data['member_id']))$mem_data['member_id_fk']=$data['member_id'];
						if(isset($data['memories']))$mem_data['memories_desc']=$data['memories'];
						$mem_data['status']='Active';
						$mem_data['created_date']=$date;
						
						$id5=$this->common_model->insert_data($table['memories'], $mem_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_college')
				{
					//var_dump($data); die();
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['college_1']))$college_data['institute_name']=$data['college_1'];
					if(isset($data['college']))$college_data['institute_id_fk']=$data['college'];
					if(isset($data['course_name']))$college_data['course_name']=$data['course_name'];
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='college';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations']))$high_data['association_desc']=$data['associations'];
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights']))$high1_data['highlight_desc']=$data['highlights'];
						$high_data['highlight_for']='College';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['supw']))$high2_data['supw_desc']=$data['supw'];
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					//supw data
					if(isset($data['achievements']))
					{
						if(isset($data['member_id']))$high4_data['member_id_fk']=$data['member_id'];
						if(isset($data['achievements']))$high4_data['award_desc']=$data['achievements'];
						$high4_data['status']='Active';
						$high4_data['created_date']=$date;
						
						$id4=$this->common_model->insert_data($table['awards'], $high4_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_pg')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['pg_1']))$college_data['institute_name']=$data['pg_1'];
					if(isset($data['pg']))$college_data['institute_id_fk']=$data['pg'];
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='pg';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations1']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations1']))$high_data['association_desc']=$data['associations1'];
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights1']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights1']))$high1_data['highlight_desc']=$data['highlights1'];
						$high_data['highlight_for']='PG';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw1']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['supw1']))$high2_data['supw_desc']=$data['supw1'];
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'professional')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['current_employer']))$college_data['profession_name']=$data['current_employer'];
					if(isset($data['designation']))$college_data['profession_designation']=$data['designation'];
					if(isset($data['period']))$college_data['profession_experience']=$data['period'];
					if(isset($data['from_date']))$college_data['profession_from_date']=$data['from_date'];
					if(isset($data['till_date']))$college_data['profession_to_date']=$data['till_date'];
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['professions'], $college_data);
					
					if(isset($data['member_id']))$college1_data['member_id_fk']=$data['member_id'];
					if(isset($data['previous_employer']))$college1_data['profession_name']=$data['previous_employer'];
					if(isset($data['designation1']))$college1_data['profession_designation']=$data['designation1'];
					if(isset($data['period1']))$college1_data['profession_experience']=$data['period1'];
					if(isset($data['from_date1']))$college1_data['profession_from_date']=$data['from_date1'];
					if(isset($data['t0_date1']))$college1_data['profession_to_date']=$data['till_date1'];
					$college1_data['status']='Active';
					$college1_data['created_date']=$date;
					
					$id1=$this->common_model->insert_data($table['professions'], $college1_data);
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'myinterest')
				{
					//hobby master data
					if(isset($data['my_hobbies']))$hob_data['hobby_desc']=$data['my_hobbies'];
		            $hob_data['hobby_status']='Active';
					$hob_data['created_date']=$date;
					$hob_data['modified_date']=$date;
					
					$id1 = $this->common_model->insert_data($table['hobby_master'], $hob_data);
					
					//hobby data
					if(isset($data['member_id']))$hob1_data['member_id_fk']=$data['member_id'];
					if(isset($id1))$hob1_data['hobby_id_fk']=$id1;
					if(isset($data['my_hobbies']))$hob1_data['hobby_name']=$data['my_hobbies'];
		            $hob1_data['hobby_status']='Active';
					$hob1_data['created_date']=$date;
					
					$id2 = $this->common_model->insert_data($table['hobbies'], $hob1_data);
					
					if(isset($data['member_id']))$hob2_data['member_id_fk']=$data['member_id'];
					if(isset($data['books_that_i_have_read']))$hob2_data['book_name']=$data['books_that_i_have_read'];
		            $hob2_data['status']='Active';
					$hob2_data['created_date']=$date;
					
					$id3 = $this->common_model->insert_data($table['book'], $hob2_data);
					
					if(isset($data['member_id']))$int_data['member_id_fk']=$data['member_id'];
					if(isset($data['my_blogs']))$int_data['blog_url']=$data['my_blogs'];
					if(isset($data['my_websites']))$int_data['web_url']=$data['my_websites'];
					//$int_data['status']='Active';
					$int_data['created_date']=$date;
					$int_data['modified_date']=$date;
					
					$id = $this->common_model->insert_data($table['interest'], $int_data);
											
					if($id){ return $id; }
					else{ return ''; }
				}
			}
			break;
			case 'parent':{
				if($data['part'] == 'personal')
				{
					if(isset($data['first_name']))$member_data['first_name'] = htmlspecialchars($data['first_name'],ENT_QUOTES);
					if(isset($data['last_name']))$member_data['last_name'] = htmlspecialchars($data['last_name'],ENT_QUOTES);
					if(isset($data['email']))$member_data['email'] = htmlspecialchars($data['email'],ENT_QUOTES);
					if(isset($data['password']))$member_data['password']=md5($data['password']);
		            $member_data['active']='N';
					if(isset($activation))
					{
						$member_data['activation']=$activation;
					}
					$member_data['created_date']=$date;
					$member_data['modified_date']=$date;
					if(isset($data['gender']))$member_data['gender'] = htmlspecialchars($data['gender'],ENT_QUOTES);
					$member_data['donor']='none';
					if(isset($data['member_type']))$member_data['member_type'] = htmlspecialchars($data['member_type'],ENT_QUOTES);
					if(isset($data['tagline']))$member_data['tagline'] = htmlspecialchars(trim($data['tagline']),ENT_QUOTES);
					if(isset($data['alias']))$member_data['alias'] = htmlspecialchars(trim($data['alias'],ENT_QUOTES));
					if(isset($data['phone_number1']))$member_data['phone_number'] = htmlspecialchars($data['phone_number1'],ENT_QUOTES);
					if(isset($data['phone_number2']) && $data['phone_number2']!='')$member_data['phone_number'].=', '.htmlspecialchars($data['phone_number2'],ENT_QUOTES);
					if(isset($data['phone_number3']) && $data['phone_number3']!='')$member_data['phone_number'].=', '.htmlspecialchars($data['phone_number3'],ENT_QUOTES);
					if(isset($data['dob']))$member_data['dob']=date('Y-m-d 00:00:00' ,strtotime($data['dob']));
					if(isset($data['home_address']))$member_data['address1'] = htmlspecialchars(trim($data['home_address']),ENT_QUOTES);
					if(isset($data['city']))$member_data['city_id_fk'] = htmlspecialchars($data['city'],ENT_QUOTES);
					if(isset($data['city_1']))$member_data['city_name'] = htmlspecialchars($data['city_1'],ENT_QUOTES);
					if(isset($data['state']))$member_data['state_id_fk'] = htmlspecialchars($data['state'],ENT_QUOTES);
					if(isset($data['country']))$member_data['country_id_fk']=htmlspecialchars($data['country'],ENT_QUOTES);
					if(isset($data['postal_code']))$member_data['pin_code'] = htmlspecialchars($data['postal_code'],ENT_QUOTES);
					//insert member data
					$id=$this->common_model->insert_data($table['member'], $member_data);
					if($id){ 
						 $this->email_send($data['email'],$email_message);
						return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_school')
				{
					//var_dump($data); die();
					//school data
					if(isset($data['member_id']))$school_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['school_1']))$school_data['school_name'] = htmlspecialchars($data['school_1'],ENT_QUOTES);
					if(isset($data['school']))$school_data['school_id_fk'] = htmlspecialchars($data['school'],ENT_QUOTES);
					if(isset($data['section']))$school_data['section'] = htmlspecialchars($data['section'],ENT_QUOTES);
					if(isset($data['admission_no']))$school_data['admission_no'] = htmlspecialchars($data['admission_no'],ENT_QUOTES);
					if(isset($data['year_start']))$school_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$school_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
		            $school_data['status']='Active';
					$school_data['created_date']=$date;
					$school_data['modified_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['school'], $school_data);
					//class data
					if(isset($data['member_id']))$class_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					$class_data['class_id_fk'] = htmlspecialchars($data['class'],ENT_QUOTES);
					$class_data['created_date']=$date;
					$class_data['modified_date']=$date;
					//insert school data
					$id4=$this->common_model->insert_data($table['class'], $class_data);
					
					//highlight1 data
					if(isset($data['highlights']) && $data['highlights']!='')
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights']))$high_data['highlight_desc'] = htmlspecialchars($data['highlights'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						$id1=$this->common_model->insert_data($table['highlight'], $high_data);
					}
					//highlight2 data
					if(isset($data['highlight2']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlight2']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlight2'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//highlight3 data
					if(isset($data['highlight3']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlight3']))$high2_data['highlight_desc'] = htmlspecialchars($data['highlight3'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high2_data['status']='Active';
						$high2_data['created_date']=$date;
						
						$id3=$this->common_model->insert_data($table['highlight'], $high2_data);
					}
					
					//memories data
					if(isset($data['memories']))
					{
						if(isset($data['member_id']))$mem_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['memories']))$mem_data['memories_desc'] = htmlspecialchars($data['memories'],ENT_QUOTES);
						$mem_data['status']='Active';
						$mem_data['created_date']=$date;
						
						$id5=$this->common_model->insert_data($table['memories'], $mem_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_college')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['college_1']))$college_data['institute_name'] = htmlspecialchars($data['college_1'],ENT_QUOTES);
					if(isset($data['college']))$college_data['institute_id_fk'] = htmlspecialchars($data['college'],ENT_QUOTES);
					if(isset($data['course_name']))$college_data['course_name'] = htmlspecialchars($data['course_name'],ENT_QUOTES);
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='college';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations']))$high_data['association_desc'] = htmlspecialchars($data['associations'],ENT_QUOTES);
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlights'],ENT_QUOTES);
						$high_data['highlight_for']='College';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['supw']))$high2_data['supw_desc'] = htmlspecialchars($data['supw'],ENT_QUOTES);
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					//supw data
					if(isset($data['achievements']))
					{
						if(isset($data['member_id']))$high4_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['achievements']))$high4_data['award_desc'] = htmlspecialchars($data['achievements'],ENT_QUOTES);
						$high4_data['status']='Active';
						$high4_data['created_date']=$date;
						
						$id4=$this->common_model->insert_data($table['awards'], $high4_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_pg')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['pg_1']))$college_data['institute_name'] = htmlspecialchars($data['pg_1'],ENT_QUOTES);
					if(isset($data['pg']))$college_data['institute_id_fk'] = htmlspecialchars($data['pg'],ENT_QUOTES);
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='pg';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations1']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations1']))$high_data['association_desc'] = htmlspecialchars($data['associations1'],ENT_QUOTES);
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights1']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights1']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlights1'],ENT_QUOTES);
						$high_data['highlight_for']='PG';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw1']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['supw1']))$high2_data['supw_desc'] = htmlspecialchars($data['supw1'],ENT_QUOTES);
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'professional')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['current_employer']))$college_data['profession_name'] = htmlspecialchars($data['current_employer'],ENT_QUOTES);
					if(isset($data['designation']))$college_data['profession_designation'] = htmlspecialchars($data['designation'],ENT_QUOTES);
					if(isset($data['period']))$college_data['profession_experience'] = htmlspecialchars($data['period'],ENT_QUOTES);
					if(isset($data['from_date']))$college_data['profession_from_date'] = htmlspecialchars($data['from_date'],ENT_QUOTES);
					if(isset($data['till_date']))$college_data['profession_to_date'] = htmlspecialchars($data['till_date'],ENT_QUOTES);
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['professions'], $college_data);
					
					if(isset($data['member_id']))$college1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['previous_employer']))$college1_data['profession_name'] = htmlspecialchars($data['previous_employer'],ENT_QUOTES);
					if(isset($data['designation1']))$college1_data['profession_designation'] = htmlspecialchars($data['designation1'],ENT_QUOTES);
					if(isset($data['period1']))$college1_data['profession_experience'] = htmlspecialchars($data['period1'],ENT_QUOTES);
					if(isset($data['from_date1']))$college1_data['profession_from_date'] = htmlspecialchars($data['from_date1'],ENT_QUOTES);
					if(isset($data['t0_date1']))$college1_data['profession_to_date'] = htmlspecialchars($data['till_date1'],ENT_QUOTES);
					$college1_data['status']='Active';
					$college1_data['created_date']=$date;
					
					$id1=$this->common_model->insert_data($table['professions'], $college1_data);
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'myinterest')
				{
					//hobby master data
					if(isset($data['my_hobbies']))$hob_data['hobby_desc'] = htmlspecialchars($data['my_hobbies'],ENT_QUOTES);
		            $hob_data['hobby_status']='Active';
					$hob_data['created_date']=$date;
					$hob_data['modified_date']=$date;
					
					$id1 = $this->common_model->insert_data($table['hobby_master'], $hob_data);
					
					//hobby data
					if(isset($data['member_id']))$hob1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($id1))$hob1_data['hobby_id_fk']=$id1;
					if(isset($data['my_hobbies']))$hob1_data['hobby_name'] = htmlspecialchars($data['my_hobbies'],ENT_QUOTES);
		            $hob1_data['hobby_status']='Active';
					$hob1_data['created_date']=$date;
					
					$id2 = $this->common_model->insert_data($table['hobbies'], $hob1_data);
					
					if(isset($data['member_id']))$hob2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['books_that_i_have_read']))$hob2_data['book_name'] = htmlspecialchars($data['books_that_i_have_read'],ENT_QUOTES);
		            $hob2_data['status']='Active';
					$hob2_data['created_date']=$date;
					
					$id3 = $this->common_model->insert_data($table['book'], $hob2_data);
					
					if(isset($data['member_id']))$int_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['my_blogs']))$int_data['blog_url'] = htmlspecialchars($data['my_blogs'],ENT_QUOTES);
					if(isset($data['my_websites']))$int_data['web_url'] = htmlspecialchars($data['my_websites'],ENT_QUOTES);
					//$int_data['status']='Active';
					$int_data['created_date']=$date;
					$int_data['modified_date']=$date;
					
					$id = $this->common_model->insert_data($table['interest'], $int_data);
											
					if($id){ return $id; }
					else{ return ''; }
				}
				
			}
			case 'teacher':
			{
				if($data['part'] == 'personal')
				{
					//member data
					if(isset($data['first_name']))$member_data['first_name'] = htmlspecialchars($data['first_name'],ENT_QUOTES);
					if(isset($data['last_name']))$member_data['last_name'] = htmlspecialchars($data['last_name'],ENT_QUOTES);
					if(isset($data['email']))$member_data['email'] = htmlspecialchars($data['email'],ENT_QUOTES);
					if(isset($data['password']))$member_data['password']=md5($data['password']);
		            $member_data['active']='N';
					if(isset($activation))
					{
						$member_data['activation']=$activation;
					}
					$member_data['created_date']=$date;
					$member_data['modified_date']=$date;
					if(isset($data['gender']))$member_data['gender'] = htmlspecialchars($data['gender'],ENT_QUOTES);
					$member_data['donor']='none';
					if(isset($data['member_type']))$member_data['member_type'] = htmlspecialchars($data['member_type'],ENT_QUOTES);
					if(isset($data['tagline']))$member_data['tagline'] = htmlspecialchars(trim($data['tagline']),ENT_QUOTES);
					if(isset($data['alias']))$member_data['alias'] = htmlspecialchars(trim($data['alias'],ENT_QUOTES));
					if(isset($data['phone_number1']))$member_data['phone_number'] = htmlspecialchars($data['phone_number1'],ENT_QUOTES);
					if(isset($data['phone_number2']) && $data['phone_number2']!='')$member_data['phone_number'].=', '.htmlspecialchars($data['phone_number2'],ENT_QUOTES);
					if(isset($data['phone_number3']) && $data['phone_number3']!='')$member_data['phone_number'].=', '.htmlspecialchars($data['phone_number3'],ENT_QUOTES);
					if(isset($data['dob']))$member_data['dob']=date('Y-m-d 00:00:00' ,strtotime($data['dob']));
					if(isset($data['home_address']))$member_data['address1'] = htmlspecialchars(trim($data['home_address']),ENT_QUOTES);
					if(isset($data['city']))$member_data['city_id_fk'] = htmlspecialchars($data['city'],ENT_QUOTES);
					if(isset($data['city_1']))$member_data['city_name'] = htmlspecialchars($data['city_1'],ENT_QUOTES);
					if(isset($data['country']))$member_data['country_id_fk']=htmlspecialchars($data['country'],ENT_QUOTES);
					if(isset($data['state']))$member_data['state_id_fk'] = htmlspecialchars($data['state'],ENT_QUOTES);
					if(isset($data['postal_code']))$member_data['pin_code'] = htmlspecialchars($data['postal_code'],ENT_QUOTES);
					//insert member data
				//	var_dump($data['email']); die();
					$id=$this->common_model->insert_data($table['member'], $member_data);
					
					if($id){ 
					 $this->email_send($data['email'],$email_message);
						return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_school')
				{
					//school data
					if(isset($data['member_id']))$school_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['school_1']))$school_data['school_name'] = htmlspecialchars($data['school_1'],ENT_QUOTES);
					if(isset($data['school']))$school_data['school_id_fk'] = htmlspecialchars($data['school'],ENT_QUOTES);
					if(isset($data['section']))$school_data['section'] = htmlspecialchars($data['section'],ENT_QUOTES);
					if(isset($data['admission_no']))$school_data['admission_no'] = htmlspecialchars($data['admission_no'],ENT_QUOTES);
					if(isset($data['year_start']))$school_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$school_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$school_data['status']='Active';
					$school_data['created_date']=$date;
					$school_data['modified_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['school'], $school_data);
					//class data
					if(isset($data['member_id']))$class_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					$class_data['class_id_fk'] = htmlspecialchars($data['class'],ENT_QUOTES);
					$class_data['created_date']=$date;
					$class_data['modified_date']=$date;
					//insert school data
					$id4=$this->common_model->insert_data($table['class'], $class_data);
					
					//highlight1 data
					if(isset($data['highlights']) && $data['highlights']!='')
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights']))$high_data['highlight_desc'] = htmlspecialchars($data['highlights'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						$id1=$this->common_model->insert_data($table['highlight'], $high_data);
					}
					//highlight2 data
					if(isset($data['highlight2']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlight2']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlight2'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//highlight3 data
					if(isset($data['highlight3']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlight3']))$high2_data['highlight_desc'] = htmlspecialchars($data['highlight3'],ENT_QUOTES);
						$high_data['highlight_for']='School';
						$high2_data['status']='Active';
						$high2_data['created_date']=$date;
						
						$id3=$this->common_model->insert_data($table['highlight'], $high2_data);
					}
					
					//memories data
					if(isset($data['memories']))
					{
						if(isset($data['member_id']))$mem_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['memories']))$mem_data['memories_desc'] = htmlspecialchars($data['memories'],ENT_QUOTES);
						$mem_data['status']='Active';
						$mem_data['created_date']=$date;
						
						$id5=$this->common_model->insert_data($table['memories'], $mem_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_college')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['college_1']))$college_data['institute_name'] = htmlspecialchars($data['college_1'],ENT_QUOTES);
					if(isset($data['college']))$college_data['institute_id_fk'] = htmlspecialchars($data['college'],ENT_QUOTES);
					if(isset($data['course_name']))$college_data['course_name'] = htmlspecialchars($data['course_name'],ENT_QUOTES);
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='college';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations']))$high_data['association_desc'] = htmlspecialchars($data['associations'],ENT_QUOTES);
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlights'],ENT_QUOTES);
						$high_data['highlight_for']='College';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['supw']))$high2_data['supw_desc'] = htmlspecialchars($data['supw'],ENT_QUOTES);
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					//supw data
					if(isset($data['achievements']))
					{
						if(isset($data['member_id']))$high4_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['achievements']))$high4_data['award_desc'] = htmlspecialchars($data['achievements'],ENT_QUOTES);
						$high4_data['status']='Active';
						$high4_data['created_date']=$date;
						
						$id4=$this->common_model->insert_data($table['awards'], $high4_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_pg')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['pg_1']))$college_data['institute_name'] = htmlspecialchars($data['pg_1'],ENT_QUOTES);
					if(isset($data['pg']))$college_data['institute_id_fk'] = htmlspecialchars($data['pg'],ENT_QUOTES);
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					
					$college_data['type']='pg';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations1']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations1']))$high_data['association_desc'] = htmlspecialchars($data['associations1'],ENT_QUOTES);
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights1']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['highlights1']))$high1_data['highlight_desc'] = htmlspecialchars($data['highlights1'],ENT_QUOTES);
						$high_data['highlight_for']='PG';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw1']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
						if(isset($data['supw1']))$high2_data['supw_desc'] = htmlspecialchars($data['supw1'],ENT_QUOTES);
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'professional')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['current_employer']))$college_data['profession_name'] = htmlspecialchars($data['current_employer'],ENT_QUOTES);
					if(isset($data['designation']))$college_data['profession_designation'] = htmlspecialchars($data['designation'],ENT_QUOTES);
					if(isset($data['period']))$college_data['profession_experience'] = htmlspecialchars($data['period'],ENT_QUOTES);
					if(isset($data['from_date']))$college_data['profession_from_date'] = htmlspecialchars($data['from_date'],ENT_QUOTES);
					if(isset($data['till_date']))$college_data['profession_to_date'] = htmlspecialchars($data['till_date'],ENT_QUOTES);
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['professions'], $college_data);
					
					if(isset($data['member_id']))$college1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['previous_employer']))$college1_data['profession_name'] = htmlspecialchars($data['previous_employer'],ENT_QUOTES);
					if(isset($data['designation1']))$college1_data['profession_designation'] = htmlspecialchars($data['designation1'],ENT_QUOTES);
					if(isset($data['period1']))$college1_data['profession_experience'] = htmlspecialchars($data['period1'],ENT_QUOTES);
					if(isset($data['from_date1']))$college1_data['profession_from_date'] = htmlspecialchars($data['from_date1'],ENT_QUOTES);
					if(isset($data['t0_date1']))$college1_data['profession_to_date'] = htmlspecialchars($data['till_date1'],ENT_QUOTES);
					$college1_data['status']='Active';
					$college1_data['created_date']=$date;
					
					$id1=$this->common_model->insert_data($table['professions'], $college1_data);
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'myinterest')
				{
					//hobby master data
					if(isset($data['my_hobbies']))$hob_data['hobby_desc'] = htmlspecialchars($data['my_hobbies'],ENT_QUOTES);
		            $hob_data['hobby_status']='Active';
					$hob_data['created_date']=$date;
					$hob_data['modified_date']=$date;
					
					$id1 = $this->common_model->insert_data($table['hobby_master'], $hob_data);
					
					//hobby data
					if(isset($data['member_id']))$hob1_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($id1))$hob1_data['hobby_id_fk']=$id1;
					if(isset($data['my_hobbies']))$hob1_data['hobby_name'] = htmlspecialchars($data['my_hobbies'],ENT_QUOTES);
		            $hob1_data['hobby_status']='Active';
					$hob1_data['created_date']=$date;
					
					$id2 = $this->common_model->insert_data($table['hobbies'], $hob1_data);
					
					if(isset($data['member_id']))$hob2_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['books_that_i_have_read']))$hob2_data['book_name'] = htmlspecialchars($data['books_that_i_have_read'],ENT_QUOTES);
		            $hob2_data['status']='Active';
					$hob2_data['created_date']=$date;
					
					$id3 = $this->common_model->insert_data($table['book'], $hob2_data);
					
					if(isset($data['member_id']))$int_data['member_id_fk'] = htmlspecialchars($data['member_id'],ENT_QUOTES);
					if(isset($data['my_blogs']))$int_data['blog_url'] = htmlspecialchars($data['my_blogs'],ENT_QUOTES);
					if(isset($data['my_websites']))$int_data['web_url'] = htmlspecialchars($data['my_websites'],ENT_QUOTES);
					//$int_data['status']='Active';
					$int_data['created_date']=$date;
					$int_data['modified_date']=$date;
					
					$id = $this->common_model->insert_data($table['interest'], $int_data);
											
					if($id){ return $id; }
					else{ return ''; }
				}
			}
			break;
			case 'institute':{
				
				if(isset($data['first_name']))$member_data['first_name']=htmlspecialchars($data['first_name'],ENT_QUOTES);
				if(isset($data['last_name']))$member_data['last_name']=htmlspecialchars($data['last_name'],ENT_QUOTES);
				if(isset($data['email']))$member_data['email']=htmlspecialchars($data['email'],ENT_QUOTES);
				if(isset($data['password']))$member_data['password']=md5($data['password']);
				if(isset($data['member_type']))$member_data['member_type']=$data['member_type'];
				if(isset($data['tagline']))$member_data['tagline']=htmlspecialchars(trim($data['tagline']),ENT_QUOTES);
				if(isset($data['alias']))$member_data['alias']=htmlspecialchars(trim($data['alias']),ENT_QUOTES);
				if(isset($data['phone_number1']))$member_data['phone_number']=htmlspecialchars($data['phone_number1'],ENT_QUOTES);
				if(isset($data['phone_number2']) && $data['phone_number2']!='')$member_data['phone_number'].=htmlspecialchars($data['phone_number2'],ENT_QUOTES);
				if(isset($data['phone_number3']) && $data['phone_number3']!='')$member_data['phone_number'].=htmlspecialchars($data['phone_number3'],ENT_QUOTES);
				if(isset($data['state']))$member_data['state_id_fk']=trim($data['state']);
				if(isset($data['city']))$member_data['city_id_fk']=trim($data['city']);
				if(isset($data['city_1']))$member_data['city_name']=trim($data['city_1']);
				if(isset($data['country']))$member_data['country_id_fk']=htmlspecialchars($data['country'],ENT_QUOTES);
				if(isset($data['Address']))$member_data['address1']=htmlspecialchars(trim($data['Address']),ENT_QUOTES);
				if(isset($data['postal_code']))$member_data['pin_code']=htmlspecialchars(trim($data['postal_code']),ENT_QUOTES);
				
				$member_data['created_date'] = $date;
				$member_data['active']='N';
					if(isset($activation))
					{
						$member_data['activation']=$activation;
					}
					$member_data['created_date']=$date;
					$member_data['modified_date']=$date;
					$member_data['donor']='none';
					
				$id_m = $this->common_model->insert_data($table['member'], $member_data);
				if(isset($id_m)){
					$member_data1['member_id_fk'] = $id_m;
						if(isset($data['Shortname'])) $member_data1['shortname']=htmlspecialchars($data['Shortname'],ENT_QUOTES);
						if(isset($data['Founded_in'])) $member_data1['founded_in']=htmlspecialchars($data['Founded_in'],ENT_QUOTES);
						if(isset($data['Branches1'])) $member_data1['Branches']=htmlspecialchars($data['Branches1'],ENT_QUOTES);
						if(isset($data['Branches2'])) $member_data1['Branches'].=', '.htmlspecialchars($data['Branches2'],ENT_QUOTES);
						if(isset($data['Branches3'])) $member_data1['Branches'].=', '.htmlspecialchars($data['Branches3'],ENT_QUOTES);
						if(isset($data['About_Us'])) $member_data1['About_Us']=htmlspecialchars($data['About_Us'],ENT_QUOTES);
						if(isset($data['Institution_Head'])) $member_data1['Institution_Head']=htmlspecialchars($data['Institution_Head'],ENT_QUOTES);
						if(isset($data['Management_Team1'])) $member_data1['Management_Team']=htmlspecialchars($data['Management_Team1'],ENT_QUOTES);
						if(isset($data['Management_Team2']) && $data['Management_Team2']!='') $member_data1['Management_Team'].=', '.htmlspecialchars($data['Management_Team2'],ENT_QUOTES);
						if(isset($data['Management_Team3']) && $data['Management_Team3']!='') $member_data1['Management_Team'].=', '.htmlspecialchars($data['Management_Team1'],ENT_QUOTES);
						if(isset($data['Board_Affiliation1'])) $member_data1['Board_Affiliation']=htmlspecialchars($data['Board_Affiliation1'],ENT_QUOTES);
						if(isset($data['Board_Affiliation2']) && $data['Board_Affiliation2']!='') $member_data1['Board_Affiliation'].=', '.htmlspecialchars($data['Board_Affiliation2'],ENT_QUOTES);
						if(isset($data['Board_Affiliation3']) && $data['Board_Affiliation3']!='') $member_data1['Board_Affiliation'].=', '.htmlspecialchars($data['Board_Affiliation3'],ENT_QUOTES);
						if(isset($data['Classes'])) $member_data1['Classes']=htmlspecialchars($data['Classes'],ENT_QUOTES);
						if(isset($data['Amenities'])) $member_data1['Amenities']=htmlspecialchars($data['Amenities'],ENT_QUOTES);
						if(isset($data['Recommendations'])) $member_data1['Recommendations']=htmlspecialchars($data['Recommendations'],ENT_QUOTES);
						if(isset($data['Associations'])) $member_data1['Associations']=htmlspecialchars($data['Associations'],ENT_QUOTES);
						if(isset($data['Tournaments'])) $member_data1['Tournaments']=htmlspecialchars($data['Tournaments'],ENT_QUOTES);
						if(isset($data['Achievements'])) $member_data1['Achievements']=htmlspecialchars($data['Achievements'],ENT_QUOTES);
						if(isset($data['Internship_Opportunities'])) $member_data1['Internship_Opportunities']=htmlspecialchars($data['Internship_Opportunities'],ENT_QUOTES);
						if(isset($data['SUPW'])) $member_data1['SUPW']=htmlspecialchars($data['SUPW'],ENT_QUOTES);
						if(isset($data['institution_type'])) $member_data1['institution_type']=htmlspecialchars($data['institution_type'],ENT_QUOTES);
						if(isset($data['Date_of_Incorporation'])) $member_data1['Date_of_Incorporation']=htmlspecialchars($data['Date_of_Incorporation'],ENT_QUOTES);
						if(isset($data['Branches'])) $member_data1['Branches']=htmlspecialchars($data['Branches'],ENT_QUOTES);
						if(isset($data['Business_Head'])) $member_data1['bussiness_head']=htmlspecialchars($data['Business_Head'],ENT_QUOTES);
						if(isset($data['Products_offered'])) $member_data1['product_offered']=htmlspecialchars($data['Products_offered'],ENT_QUOTES);
						if(isset($data['Services_Offered'])) $member_data1['service_offered']=htmlspecialchars($data['Services_Offered'],ENT_QUOTES);
						//if(isset($data['Services_Offered'])) $member_data1['Services_Offered']=htmlspecialchars($data['Services_Offered'],ENT_QUOTES);
						
						$member_data1['created_date']=$date;	
						$id_m1 = $this->common_model->insert_data('intitution_details', $member_data1);
						if(isset($id_m1)){
						//mail here
							 $this->email_send($data['email'],$email_message);
							return true;
						}else {
							return false;
						}
				}
				
				
			}
			case 'educator':
			{
				if($data['part'] == 'personal')
				{
					//member data
					if(isset($data['first_name']))$member_data['first_name']=$data['first_name'];
					if(isset($data['last_name']))$member_data['last_name']=$data['last_name'];
					if(isset($data['email']))$member_data['email']=$data['email'];
					if(isset($data['password']))$member_data['password']=md5($data['password']);
		            $member_data['active']='N';
					if(isset($activation))
					{
						$member_data['activation']=$activation;
					}
					$member_data['created_date']=$date;
					$member_data['modified_date']=$date;
					if(isset($data['gender']))$member_data['gender']=$data['gender'];
					$member_data['donor']='none';
					if(isset($data['member_type']))$member_data['member_type']=$data['member_type'];
					if(isset($data['tagline']))$member_data['tagline']=trim($data['tagline']);
					if(isset($data['alias']))$member_data['alias']=trim($data['alias']);
					if(isset($data['phone_number']))$member_data['phone_number']=$data['phone_number1'];
					if(isset($data['dob']))$member_data['dob']=date('Y-m-d 00:00:00' ,strtotime($data['dob']));
					if(isset($data['home_address']))$member_data['address1']=trim($data['home_address']);
					if(isset($data['city']))$member_data['city_id_fk']=$data['city'];
					if(isset($data['city_1']))$member_data['city_name']=$data['city_1'];
					if(isset($data['country']))$member_data['country_id_fk']=htmlspecialchars($data['country'],ENT_QUOTES);
					if(isset($data['state']))$member_data['state_id_fk']=$data['state'];
					if(isset($data['postal_code']))$member_data['pin_code']=$data['postal_code'];
					
					//insert member data
					$id=$this->common_model->insert_data($table['member'], $member_data);
				    if($id){  
						 $this->email_send($data['email'],$email_message);
					return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_school')
				{
					//school data
					if(isset($data['member_id']))$school_data['member_id_fk']=$data['member_id'];
					if(isset($data['school_1']))$school_data['school_name']=$data['school_1'];
					if(isset($data['school']))$school_data['school_id_fk']=$data['school'];
					if(isset($data['section']))$school_data['section']=$data['section'];
					if(isset($data['admission_no']))$school_data['admission_no']=$data['admission_no'];
					if(isset($data['year_start']))$school_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$school_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
		            $school_data['status']='Active';
					$school_data['created_date']=$date;
					$school_data['modified_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['school'], $school_data);
					
					//class data
					if(isset($data['member_id']))$class_data['member_id_fk']=$data['member_id'];
					$class_data['class_id_fk']=$data['class'];
					$class_data['created_date']=$date;
					$class_data['modified_date']=$date;
					//insert school data
					$id4=$this->common_model->insert_data($table['class'], $class_data);
					
					//highlight1 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights']))$high_data['highlight_desc']=$data['highlights'];
						$high_data['highlight_for']='School';
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['highlight'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlight2']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlight2']))$high1_data['highlight_desc']=$data['highlight2'];
						$high_data['highlight_for']='School';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//highlight3 data
					if(isset($data['highlight3']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlight3']))$high2_data['highlight_desc']=$data['highlight3'];
						$high_data['highlight_for']='School';
						$high2_data['status']='Active';
						$high2_data['created_date']=$date;
						
						$id3=$this->common_model->insert_data($table['highlight'], $high2_data);
					}
					
					//memories data
					if(isset($data['memories']))
					{
						if(isset($data['member_id']))$mem_data['member_id_fk']=$data['member_id'];
						if(isset($data['memories']))$mem_data['memories_desc']=$data['memories'];
						$mem_data['status']='Active';
						$mem_data['created_date']=$date;
						
						$id5=$this->common_model->insert_data($table['memories'], $mem_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_college')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['college_1']))$college_data['institute_name']=$data['college_1'];
					if(isset($data['college']))$college_data['institute_id_fk']=$data['college'];
					if(isset($data['course_name']))$college_data['course_name']=$data['course_name'];
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='college';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations']))$high_data['association_desc']=$data['associations'];
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights']))$high1_data['highlight_desc']=$data['highlights'];
						$high_data['highlight_for']='College';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['supw']))$high2_data['supw_desc']=$data['supw'];
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					//supw data
					if(isset($data['achievements']))
					{
						if(isset($data['member_id']))$high4_data['member_id_fk']=$data['member_id'];
						if(isset($data['achievements']))$high4_data['award_desc']=$data['achievements'];
						$high4_data['status']='Active';
						$high4_data['created_date']=$date;
						
						$id4=$this->common_model->insert_data($table['awards'], $high4_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'academic_pg')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['pg_1']))$college_data['institute_name']=$data['pg_1'];
					if(isset($data['pg']))$college_data['institute_id_fk']=$data['pg'];
					if(isset($data['year_start']))$college_data['academic_year'] = htmlspecialchars($data['year_start'],ENT_QUOTES);
					if(isset($data['year_end']))$college_data['academic_year'] .= ' - '.htmlspecialchars($data['year_end'],ENT_QUOTES);
					$college_data['type']='pg';
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					$college_data['modified_date']=$date;
					
					//insert school data
					$id=$this->common_model->insert_data($table['institute'], $college_data);
					
					//association data
					if(isset($data['associations1']))
					{
						if(isset($data['member_id']))$high_data['member_id_fk']=$data['member_id'];
						if(isset($id))$high_data['institute_id_fk']=$id;
						if(isset($data['associations1']))$high_data['association_desc']=$data['associations1'];
						$high_data['status']='Active';
						$high_data['created_date']=$date;
						
						$id1=$this->common_model->insert_data($table['associations'], $high_data);
					}
					
					//highlight2 data
					if(isset($data['highlights1']))
					{
						if(isset($data['member_id']))$high1_data['member_id_fk']=$data['member_id'];
						if(isset($data['highlights1']))$high1_data['highlight_desc']=$data['highlights1'];
						$high_data['highlight_for']='PG';
						$high1_data['status']='Active';
						$high1_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['highlight'], $high1_data);
					}
					
					//supw data
					if(isset($data['supw1']))
					{
						if(isset($data['member_id']))$high2_data['member_id_fk']=$data['member_id'];
						if(isset($data['supw1']))$high2_data['supw_desc']=$data['supw1'];
						$high2_data['supw_status']='Active';
						$high2_data['created_date']=$date;
						
						$id2=$this->common_model->insert_data($table['supw'], $high2_data);
					}
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'professional')
				{
					//school data
					if(isset($data['member_id']))$college_data['member_id_fk']=$data['member_id'];
					if(isset($data['current_employer']))$college_data['profession_name']=$data['current_employer'];
					if(isset($data['designation']))$college_data['profession_designation']=$data['designation'];
					if(isset($data['period']))$college_data['profession_experience']=$data['period'];
					if(isset($data['from_date']))$college_data['profession_from_date']=$data['from_date'];
					if(isset($data['till_date'])){$college_data['profession_to_date']=$data['till_date']; }
					//else {  }
					
					
		            $college_data['status']='Active';
					$college_data['created_date']=$date;
					//insert school data
					$id=$this->common_model->insert_data($table['professions'], $college_data);
					
					if(isset($data['member_id']))$college1_data['member_id_fk']=$data['member_id'];
					if(isset($data['previous_employer']))$college1_data['profession_name']=$data['previous_employer'];
					if(isset($data['designation1']))$college1_data['profession_designation']=$data['designation1'];
					if(isset($data['period1']))$college1_data['profession_experience']=$data['period1'];
					if(isset($data['from_date1']))$college1_data['profession_from_date']=$data['from_date1'];
					if(isset($data['t0_date1']))$college1_data['profession_to_date']=$data['till_date1'];
					$college1_data['status']='Active';
					$college1_data['created_date']=$date;
					$id1=$this->common_model->insert_data($table['professions'], $college1_data);
					
					if($id){ return $id; }
					else{ return ''; }
				}
				if($data['part'] == 'myinterest')
				{
					//hobby master data
					if(isset($data['my_hobbies']))$hob_data['hobby_desc']=$data['my_hobbies'];
		            $hob_data['hobby_status']='Active';
					$hob_data['created_date']=$date;
					$hob_data['modified_date']=$date;
					
					$id1 = $this->common_model->insert_data($table['hobby_master'], $hob_data);
					
					//hobby data
					if(isset($data['member_id']))$hob1_data['member_id_fk']=$data['member_id'];
					if(isset($id1))$hob1_data['hobby_id_fk']=$id1;
					if(isset($data['my_hobbies']))$hob1_data['hobby_name']=$data['my_hobbies'];
		            $hob1_data['hobby_status']='Active';
					$hob1_data['created_date']=$date;
					
					$id2 = $this->common_model->insert_data($table['hobbies'], $hob1_data);
					
					if(isset($data['member_id']))$hob2_data['member_id_fk']=$data['member_id'];
					if(isset($data['books_that_i_have_read']))$hob2_data['book_name']=$data['books_that_i_have_read'];
		            $hob2_data['status']='Active';
					$hob2_data['created_date']=$date;
					
					$id3 = $this->common_model->insert_data($table['book'], $hob2_data);
					
					if(isset($data['member_id']))$int_data['member_id_fk']=$data['member_id'];
					if(isset($data['my_blogs']))$int_data['blog_url']=$data['my_blogs'];
					if(isset($data['my_websites']))$int_data['web_url']=$data['my_websites'];
					//$int_data['status']='Active';
					$int_data['created_date']=$date;
					$int_data['modified_date']=$date;
					
					$id = $this->common_model->insert_data($table['interest'], $int_data);
											
					if($id){ return $id; }
					else{ return ''; }
				}
			}
		}
	}
	public function activateAccount($value=NULL)
	{
		if (empty($value))
		{
			return FALSE;
		}
		
		$date=date('Y-m-d H:i:s');
		
		$sql_select = array('email');
		$sql_whrere=array('activation'=>$value);
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('members'));
	    $result = $query->row();
		//echo $this->db->last_query();die();
		if($query->num_rows() > 0)
		{
			$email = $query->row()->email;
		}
		else {
			$email = '';
		}
		
		//---------update---------------
		$data = array(
					'activation'=>'NULL', 
					'active'=>'Y', 
					'activate_date'=>$date
					);
		$this->db->where('activation',$value);
		$query = $this->db->update('zrc_members',$data);
		
		$email_message='Thanks for activation.';
		
		if(isset($email) && $email != '')
		{
			$this->email_send($email,$email_message);
			return true;
		}
		else {
			return false;
		}
	}
	
	public function getUserData($email)
	{
		if (empty($email))
		{
			return FALSE;
		}
				
		$sql_select = array('*');
		$sql_whrere=array('email'=>$email);
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('members'));		 
		$resultData = array();
		if($query->num_rows() > 0)
		{
			$resultData = $query->result_array();
		}
		return $resultData;
	}
	
	public function getUserDataById($value=NULL)
	{
		if (empty($value))
		{
			return FALSE;
		}
				
		$sql_select = array('*');
		$sql_whrere=array('member_id'=>$value);
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('members'));		 
		$resultData = array();
		if($query->num_rows() > 0)
		{
			$resultData = $query->result_array();
		}
		return $resultData;
	}
	
	public function email_send($email,$email_message)
		{
		$CI =& get_instance();
		//Email config 
		$emailconfig['protocol'] = $CI->config->item('protocol');
		$emailconfig['smtp_host'] = $CI->config->item('smtp_host'); 
		$emailconfig['smtp_port'] = $CI->config->item('smtp_port');
		$emailconfig['smtp_timeout'] = $CI->config->item('smtp_timeout');
		$emailconfig['smtp_user'] = $CI->config->item('smtp_user');
		$emailconfig['smtp_pass'] = $CI->config->item('smtp_pass');
		$emailconfig['
		charset']               =         $CI->config->item('charset');
				$emailconfig['newline']               =         $CI->config->item('newline');  
				$emailconfig['mailtype']              =         $CI->config->item('mailtype');
				$emailconfig['validation']            =         $CI->config->item('validation');
					//var_dump($emailconfig);die();
				$this->email->initialize($emailconfig);
				$this->email->from($this->email_setting['join_as']['reply_from'], $this->email_setting['join_as']['reply_name']);
				$this->email->to($email);
				$this->email->subject($this->email_setting['join_as']['subject']);
				$this->email->message($email_message);
				
				$this->email->send();
				
				return true;
	}
public function salt()
	{
		 $CI =& get_instance();
		 return $CI->config->item('salt');
	}
	public function base_title()
	{
		 $CI =& get_instance();
		 return $CI->config->item('base_title');
	}
	public function title_separator()
	{
		 $CI =& get_instance();
		 return $CI->config->item('title_separator');
	}
	public function short_title()
	{
		 $CI =& get_instance();
		 return $CI->config->item('short_title');
	}
	public function cache_enable()
	{
		 $CI =& get_instance();
		 return $CI->config->item('cache_enable');
	}
	public function cache_time()
	{
		 $CI =& get_instance();
		 $time=null;
		 $cache_time= $CI->config->item('cache_time');
		 if(!empty($cache_time) && is_int($cache_time)) $time=$cache_time;
		 else $time=60*24;
		 return $time;	 
	}
	
	public function upload_profile_image($image_source,$image_name,$image_type,$image_fk){
		//var_dump($image_source); die();
		//var_dump($image_name); die();
		//var_dump($image_type); die();
		//var_dump($image_fk); die();
		//var_dump(); die();
		$this->db->where('photo_master_name',$image_fk);
		$query = $this->db->get('zrc_photo_master');
		$result = $query->result_array(); 
		$photo_fk = $result[0]['photo_mastar_id'];
		$insert_data['member_id_fk'] = $this->session->userdata('insert_id');
		$this->db->where('photo_type_id_fk',$photo_fk);
		$this->db->where('file_type',$image_type);
		$this->db->where('member_id_fk',$this->session->userdata('insert_id'));
		$query1 = $this->db->get('zrc_member_photos');
		$result1 = $query1->num_rows(); 
		if($result1 > 0){
			$insert_data['file_name'] = $image_name;
			$insert_data['file_type'] = $image_type;
			$insert_data['file_path'] = $image_source;	
			$insert_data['created_date'] = date('Y-m-d h:i:s');
			$this->db->where('member_id_fk',$this->session->userdata('insert_id'));
			$this->db->where('file_type',$image_type);
			$this->db->update('zrc_member_photos',$insert_data);
			return true;
		}else {
			$insert_data['photo_type_id_fk'] = $photo_fk;
			$insert_data['file_name'] = $image_name;
			$insert_data['file_type'] = $image_type;
			$insert_data['file_path'] = $image_source;
			$insert_data['created_date'] = date('Y-m-d h:i:s');
			$this->db->insert('zrc_member_photos',$insert_data);
			return true;
		}
		
	}
	
	public function get_book_list($value='')
	{
		$sql_select = array('book_id','book_title');
		$sql_where = "(subject_id='".$value['subject']."') and class_id='".$value['class']."'";
		$query=$this->db->select($sql_select)->where($sql_where)->get($this->db->dbprefix('books'));
		$data=null;
	    if ($query->num_rows()>0)
	    {
			$count=0;
			foreach($query->result_array() as $row)
			{
				if($count%2==0)
				$data.='<span class="content_blue detail join_as_detail_book" id="'.$row['book_id'].'">'.$row['book_title'].' </span><br>';
				else $data.='<span class="content_pink detail join_as_detail_book" id="'.$row['book_id'].'">'.$row['book_title'].' </span><br>';
				$count++;
			}
	    }		
		if($data!==null)
		{		
		  return trim($data,',');
		}
		else 
		{ 
		   return  $this->lang->line('not_found');
		}
		die;
	}
}
/* End of file common_model.php */
/* Location: ./application/models/common_model.php */
